package com.tudou.api.bean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Play {
	public String statues, weburl, title;
	public int code, point;
	public Results results;
	
	public class Results{
		public Hd3gp threegphd;
	}
	public class Hd3gp{
		public double totalseconds;
		public String type;
		public Segs[] segs;
	}
	public class Segs{
		public int seconds, id, size;
		public String url;
	}
	
	public static Play parsePlay(String data){
		Play play = new Play();
		
		try {
			JSONObject jobj = new JSONObject(data);
			
			play.statues = jobj.getString("status");
			play.title = jobj.getString("title");
			play.code = jobj.getInt("code");
			play.point = jobj.getInt("point");
			
			play.results = play.new Results();
			play.results.threegphd = play.new Hd3gp();
			JSONObject jobj_result = jobj.getJSONObject("results");
			JSONObject jobj_3gphd = jobj_result.getJSONObject("3gphd");
			play.results.threegphd.totalseconds = jobj_3gphd.getDouble("totalseconds");
			play.results.threegphd.type = jobj_3gphd.getString("type");
			JSONArray jobjArr = jobj_3gphd.getJSONArray("segs");
			play.results.threegphd.segs = new Segs[jobjArr.length()];
			for(int i = 0; i < jobjArr.length(); i++){
				play.results.threegphd.segs[i] = play.new Segs();
				JSONObject jobj_i = jobjArr.getJSONObject(i);
				play.results.threegphd.segs[i].id = jobj_i.getInt("id");
				play.results.threegphd.segs[i].seconds = jobj_i.getInt("seconds");
				play.results.threegphd.segs[i].size = jobj_i.getInt("size");
				play.results.threegphd.segs[i].url = jobj_i.getString("url");
			}
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return play;
	}
}
